<?php
/**
 * Created by PhpStorm.
 * User: shaowei
 * Date: 2018/12/20
 * Time: 下午8:46
 */

namespace App\Http\Controllers;

use App\Http\Model\Hint;
use App\Http\Model\OutJson;
use App\Http\Services\AdServices;
use App\Http\Services\MsgServices;
use App\Http\Services\RoomServices;
use App\Http\Services\SuggestRoomListServices;
use App\Http\Services\UserServices;
use Illuminate\Http\Request;
use App\Lib\Response;

class AdController extends BaseController
{
    protected $requestInstance;// 请求类实例
    protected $adServices;// 广告Services
    protected $serviceMsg;
    protected $suggestRoomListServices;//推荐房间
    protected $services_user;

    public function __construct()
    {
        $this->requestInstance = new Request();
        $this->adServices = new AdServices();
        $this->serviceMsg = new MsgServices();
        $this->suggestRoomListServices = new SuggestRoomListServices();
        $this->services_user = new UserServices();
    }


    /**
     * 获取首页banner
     *
     */
    public function get_banner()
    {
        if (!$this->checkRequest()) {
            Response::returnResult(Hint::PARAM_ERROR);
        }
        $type = $this->requestData['type'] ?? 0 ;
        //获取用户id
        $userid = $this->requestData['user_id'];
        $roomId = $this->requestData['room_id'];
        if (empty($userid))
        {
            Response::returnResult(Hint::PARAM_ERROR);
        }
        $data = $this->adServices->get_banner($type,$userid,$roomId);
        Response::returnResult(Hint::SUCCESS, $data);
    }


    //获取自定义的广告页
    public function get_customer(){
        do {
            if (!$this->checkRequest()) {
                break;
            }

            $this->callCommon($this->adServices, 'get_customer', $this->requestData);

        } while (false);

        if(is_string($this->responseData)) $this->responseData = json_decode($this->responseData, true);
        Response::returnResult($this->responseData['code'], $this->responseData['data'], $this->responseData['msg']);
    }

    //获取首页推荐房间数据
    public function getSuggestRoom(){
        $suggestData = $this->suggestRoomListServices->getSuggestRoom();
        Response::returnResult(Hint::SUCCESS,$suggestData);
    }

    //根据房间热度推荐房间
    public function suggestHotRoom(){
        $userloginInfo = $this->services_user->get_current_user();
        if(empty($userloginInfo)){
            Response::returnResult(Hint::LOGIN_OUT);
        }
        $userid = $userloginInfo['user_id'];
        //获取热度推荐房间
        $data = $this->suggestRoomListServices->getHotRoom($userid);
        Response::returnResult(Hint::SUCCESS,$data);
    }
}
